package com.cola.MD5;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * @Grup:com.cola.MD5
 * @Auther:cola
 * @Data:2021/3/16-2021-03-23:27
 * @version:1.0
 */
public class MD5Demo {
    public static void main(String[] args) {
        String password="admin123456";
        String savePassword="pmq7VoTEWWLYh1ZPCDRujQ==";//存储的密文
        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            //通过MD5计算摘要
            byte[]bytes=md.digest(password.getBytes("UTF-8"));
            String mdStr=new String(bytes);
            System.out.println(mdStr);
            //a-z A-Z 0-9/BASE64编码算法
            String str= Base64.getEncoder().encodeToString(bytes);
            System.out.println(str);

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
